{{- /*
Inserting image from URL.

@param {string} src The path to the image which must be a remote, page, or global resource.
@param {string} align [left|right|center] Image align.

@returns {template.HTML}

@examples

  {{< img src="https://example.com/image.png" />}}

  {{< img src="https://example.com/image.png" >}}Image caption.{{< /img >}}

  {{< img src="https://example.com/image.png" align="left" >}}Image caption.{{< /img >}}
*/ -}}

{{- if (.Get 0) -}}

    {{ $file := (.Get "src") }}
    {{ $align := (.Get "align") }}
    {{ $aligner := (slice "left" "right" "center") }}
    {{ $caption := ((.Inner) | markdownify) }}

    {{ with ($align) }}
        {{ if (not (in ($aligner) .)) }}
            {{ (errorf "The align passed to the %q shortcode is invalid. The align must be one of %s. See %s." ($.Name) (delimit ($aligner) ", " ", or ") ($.Position)) }}
        {{ end }}
    {{ end }}

    {{ if (eq ($align) "right") }}{{ $align = "float-end ms-3" }}{{ end }}
    {{ if (eq ($align) "left") }}{{ $align = "float-start me-3" }}{{ end }}
    {{ if (eq ($align) "center") }}{{ $align = "d-flex justify-content-center" }}{{ end }}

    <div class="shortcode shortcode-{{ ($.Name) }} {{ ($align) }}">
      <figure class="figure">
        <a title="{{ ($caption) }}" class="d-block" href="{{ ($file) }}"
           rel="noopener nofollow" data-fancybox="gallery" data-caption="{{ ($caption) }}">
          <img class="figure-img img-fluid rounded" src="{{ ($file) }}" alt="{{ ($file) }}" loading="lazy"/>
        </a>
          {{ with ($caption) }}
            <figcaption class="figure-caption">{{ . }}</figcaption>
          {{ end }}
      </figure>
    </div>

{{- else -}}

    {{ (partial "alerts/no_params" .) }}

{{- end -}}
